package core;
import java.awt.Color;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Transparency;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;

import javax.swing.JFrame;

public class Window extends JFrame implements ComponentListener {
	public static Window window;
	public VolatileImage _vimage;
	
	public Window() {
		window = this;
		setTitle("Space");
		setResizable(true);
		setIgnoreRepaint(true);
		setUndecorated(false);
		setVisible(true);
		setBackground(Color.BLACK);
		addComponentListener(this);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(800, 800);
//		setWindowMode();
		_vimage = createVolatileImage();
	}

	public VolatileImage createVolatileImage() {	
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
		VolatileImage image = null;
	 
		image = gc.createCompatibleVolatileImage(getWidth(), getHeight(), Transparency.OPAQUE);
		int valid = image.validate(gc);
	 
		if (valid == VolatileImage.IMAGE_INCOMPATIBLE) {
			image = createVolatileImage();
			return image;
		}
	 
		return image;
	}

//	public void setFullScreenMode() {
//		GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this);
//		createBuffer();
//	}
//
//	public void setWindowMode() {
//		GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null);
//		createBuffer();
//	}

	public void componentHidden(ComponentEvent e) {
	}

	public void componentMoved(ComponentEvent e) {
	}

	public void componentResized(ComponentEvent e) {
//		vimage = createVolatileImage();
	}

	public void componentShown(ComponentEvent e) {
	}

//	public VolatileImage getBuffer() {
//		return vimage;
//	}

	public static Window getInstance() {
		return window;
	}
}
